$(document).ready(function() {
	buildCatalogTree();
});

function buildCatalogTree() {
	var url = "tree.action";
	jQuery.post(url, {siteId:1}, function(_response, textStatus, jqXHR) {
		if (_response && _response.length > 0) {
			
			var setting = {
					data: {
						simpleData: {
							enable: true,
							pIdKey:"pid"
						}
					}
			};
			
			$.fn.zTree.init($("#catalogTree"), setting, _response);
		}
	}, "json").fail(function(){
		alert("系统异常");
	});		
}

function createCatalog() {
	var createUrl = "cview.action";
	var options = {title:"创建目录",
			ok:function(){
				var iframe = this.iframe.contentWindow;
				var form = iframe.document.getElementById('catalogForm');
				var formObj = $(form);
				var formOptions = {
						url : "create.action",
						dataType : "json",
						contentType : "application/x-www-form-urlencoded; charset=UTF-8",
						cache : false,
						type : "POST",
						beforeSend : function(XMLHttpRequest) {

						},
						beforeSubmit:function(){},
						success : function(result, textStatus){
							alert("suc");
							art.dialog.close(); 
						},
						error : function() {}
						
				}
				
				formObj.validate({
					rules:{
						name:"required",
						path:"required",
						type:"required"
					},
					messages:{
						name:"必须输入名称",
						path:"必须输入目录",
						type:"必须输入类型"
					}
				});
				
				
				var v = formObj.valid();
				alert(v);
				if (v) {
					formObj.ajaxSubmit(formOptions);
				}
				
				return false;
				
			},
			cancel:true};
	art.dialog.open(createUrl, options, false);
	
//    ok: function () {
//    	var iframe = this.iframe.contentWindow;
//    	if (!iframe.document.body) {
//        	alert('iframe还没加载完毕呢')
//        	return false;
//        };
//    	var form = iframe.document.getElementById('login-form'),
//            username = iframe.document.getElementById('login-form-username'),
//    		password = iframe.document.getElementById('login-form-password');
//        if (check(username) && check(password)) form.submit();
//       	return false;
//    },
//    cancel: true
}